package cn.yulezhisi.web.controller;

import cn.yulezhisi.common.beans.PageResultBean;
import cn.yulezhisi.common.beans.ResultBean;
import cn.yulezhisi.entity.SysUser;
import cn.yulezhisi.activiti.service.SysUserService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author yulezhisi
 **/

@Api(tags = "用户")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@RequestMapping("/user")
@Controller()
public class SysUserController{
    
    private final SysUserService sysUserService;
    
    @ApiOperation("增加")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public ResultBean add(SysUser user) {
        return new ResultBean<>(sysUserService.add(user) != null ? "success" : "fail");
    }
    
    @ApiOperation("删除")
    @RequestMapping(value = "/del", method = RequestMethod.DELETE)
    @ResponseBody
    public ResultBean delete(SysUser user) {
        return new ResultBean<>(sysUserService.delete(user) != 0 ? "success" : "fail");
    }
    
    @ApiOperation("修改")
    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    @ResponseBody
    public ResultBean update(SysUser user) {
        return new ResultBean<>(sysUserService.update(user) != 0 ? "success" : "fail");
    }
    
    @ApiOperation("查询单个")
    @RequestMapping(value = "/query", method = RequestMethod.GET)
    @ResponseBody
    public ResultBean<SysUser> findOne(SysUser user) {
        return new ResultBean<>(sysUserService.queryOne(user));
    }
    
    @ApiOperation("简单条件查询分页")
    @ResponseBody
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public PageResultBean<SysUser> findPageList(SysUser user, @RequestParam int page, @RequestParam int limit) {
        PageInfo<SysUser> pageInfo = sysUserService.queryListByPage(user, page, limit);
        return new PageResultBean<>(pageInfo.getTotal(), pageInfo.getList());
    }
    
}

























